Skip to content

Fix python state before / state after changes detection #1919

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 10, 2023

Conversation

tamarinvs19
Copy link
Collaborator

Description

After PR #1844 comparison algorithm of python objects had been changed but comparison in state before / state after differences detector hadn't been. I fixed it.

Fixes #986

How to test

Manual tests

  1. Write method which can change some class field or function which change one of the arguments. For example,
class A:
    def __init__(self, x: int):
        self.x = x
    def inc(self):  # test me 
        self.x += 1

or

def my_append(xs: list[int]):
    xs.append(1)
  1. Generate tests
  2. Expected: assertions for x-field and xs-argument have been created
class TestA(unittest.TestCase):
    def test_inc(self):
        a = copyreg._reconstructor(samples.arithmetic.A, builtins.object, None)
        a.x = -170141183460469231731687303715884105728
        actual = a.inc()
        self.assertEqual(None, actual)
        
        actual_x = a.x
        expected_x = a.x
        self.assertEqual(expected_x, actual_x)

and

class TestTopLevelFunctions(unittest.TestCase):
    def test_my_append(self):
        xs = [-170141183460469231731687303715884105728]
        actual = samples.arithmetic.my_append(xs)
        self.assertEqual(None, actual)

        self.assertEqual([-170141183460469231731687303715884105728, 1], xs)

Self-check list

Check off the item if the statement is true. Hint: [x] is a marked item.

Please do not delete the list or its items.

  • I've set the proper labels for my PR (at least, for category and component).
  • PR title and description are clear and intelligible.
  • I've added enough comments to my code, particularly in hard-to-understand areas.
  • The functionality I've repaired, changed or added is covered with automated tests.
  • Manual tests have been provided optionally.
  • The documentation for the functionality I've been working on is up-to-date.

@tamarinvs19 tamarinvs19 added comp-codegen Issue is related to code generator lang-python Issue is related to python support ctg-bug-fix PR is fixing a bug labels Mar 9, 2023
@tamarinvs19 tamarinvs19 requested a review from tochilinak March 9, 2023 21:15
@tamarinvs19 tamarinvs19 self-assigned this Mar 9, 2023
@tochilinak tochilinak merged commit d37dd07 into main Mar 10, 2023
@tochilinak tochilinak deleted the tamarinvs19/python-fix-state-comparison branch March 10, 2023 07:21
tamarinvs19 added a commit that referenced this pull request Mar 15, 2023
@alisevych alisevych added this to the 2023.03 Release milestone Mar 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp-codegen Issue is related to code generator ctg-bug-fix PR is fixing a bug lang-python Issue is related to python support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

State before and state after asserts for UtBot Python
3 participants